﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Collections.ObjectModel;
namespace SpyTxT
{
    [Serializable]
    public class Counter
    {
        [XmlElement("cargo")]
        public string cargo;
        [XmlElement("car")]
        public string car;
        [XmlElement("sum")]
        public string sum;

    }
    [Serializable]
    public class Friend
    {
        [XmlElement("id")]
        public string id;
        [XmlElement("userid")]
        public string userid;
        [XmlElement("unitname")]
        public string unitname;
        [XmlElement("friendid")]
        public string friendid;
        [XmlElement("dtadd")]
        public string dtadd;

    }
    [Serializable]
    public class PeiHuoData
    {
        [XmlElement("mark")]
        public string mark;
        [XmlElement("count")]
        public string count;
        [XmlElement("firstrow")]
        public string firstrow;


        [XmlElement("fc")]
        public string fc;
        [XmlElement("bc")]
        public string bc;


        [XmlElement("dc")]
        public string dc;
        [XmlElement("db")]
        public string db;
        [XmlElement("mc")]
        public string mc;
        [XmlElement("mb")]
        public string mb;
        [XmlElement("mr")]
        public string mr;
        [XmlElement("ar")]
        public string ar;
        [XmlElement("pt")]
        public string pt;
        [XmlElement("rt")]
        public string rt;

        [XmlElement("forbid")]
        public string forbid;
        [XmlElement("stw")]
        public string stw;

        [XmlElement("city")]
        public string city;
        [XmlElement("countys")]
        public string countys;

        [XmlText]
        public string ticketid;

        [XmlElement("counter")]
        public Counter counter;

        private List<PeiHuoTemple> peihuolist = new List<PeiHuoTemple>();

        [XmlElement("peihuo", Type = typeof(PeiHuoTemple))]
        public List<PeiHuoTemple> _peihuolist
        {
            get { return this.peihuolist; }
            set { this.peihuolist = value; }
        }

        private List<Friend> friendlist = new List<Friend>();

        [XmlElement("friend", Type = typeof(Friend))]
        public List<Friend> _friendlist
        {
            get { return this.friendlist; }
            set { this.friendlist = value; }
        }
        
    }

    [Serializable]
    [XmlRoot("commblock")]
    public class commblock
    {
        [XmlElement("id")]
        public string id;
        [XmlElement("re")]
        public string re;
        [XmlElement("command")]
        public string command;
        [XmlElement("data")]
        public PeiHuoData peihuodata;

      

    }
    [Serializable]
    [XmlRootAttribute("peihuo")]
    public class PeiHuo
    {
        public PeiHuoTemple peihuoitem{get;set;}
    }
    [Serializable]
    public class PeiHuoTemple
    {
        [XmlElement("id")]
        public string id{get;set;}
        [XmlElement("types")]
        public string type{get;set;}
        [XmlElement("postcity")]
        public string postcity{get;set;}
        [XmlElement("fromprov")]
        public string fromprov{get;set;}
        [XmlElement("fromcity")]
        public string fromcity{get;set;}
        [XmlElement("tocity")]
        public string tocity{get;set;}
        [XmlElement("linkman")]
        public string linkman{get;set;}
        [XmlElement("dtinfo")]
        public string dtinfo{get;set;}
        [XmlElement("userid")]
        public string userid{get;set;}
        [XmlElement("innerphone")]
        public string innerphone{get;set;}
        [XmlElement("datafrom")]
        public string datafrom{get;set;}
        [XmlElement("content")]
        public string content{get;set;}
        [XmlElement("tel")]
        public string tel{get;set;}
    }
    public class PeiHuoListTemple : ObservableCollection<PeiHuoTemple>
    {
        public PeiHuoListTemple()
        {

        }
    }
    public class LookCityInfro
    {
        public string maxcountinfrocity;
        public string curlookinfrorow;
    }
    class CityPeiHuoManager: UIAction,IInitUIAction
    {
        private Dictionary<string, PeiHuoListTemple> peihuolistincity = new Dictionary<string, PeiHuoListTemple>();
        private Dictionary<string, LookCityInfro> maxcountinfrocity = new Dictionary<string, LookCityInfro>();
        public void InitUIAction(IUIAction p)
        {
            this.SetUIAction(p);
        }
        public PeiHuoListTemple GetPeiHuoByCity(string cityname)
        {
            if (peihuolistincity.ContainsKey(cityname) == false)
            {
                peihuolistincity[cityname] = new PeiHuoListTemple();
            }
            return peihuolistincity[cityname];
        }
        public void AddPeiHuo(PeiHuoTemple peihuotemple, string cityname)
        {
           
            if (peihuolistincity.ContainsKey(cityname) == false)
            {
                peihuolistincity[cityname] = new PeiHuoListTemple();
            }

            if (peihuolistincity[cityname].Count > 5000)
            {
                peihuolistincity[cityname].Clear();
            }

            peihuolistincity[cityname].Insert(0, peihuotemple);
            
            //peihuolistincity[cityname].Add(peihuotemple);

        }

        public void SetMaxCountInfroByCity(string maxcount,string cityname)
        {
            if(maxcountinfrocity.ContainsKey(cityname) == false)
            {
                maxcountinfrocity[cityname] = new LookCityInfro();
            }
            maxcountinfrocity[cityname].maxcountinfrocity = maxcount;
            
        }

        public string GetMaxCountInfroByCity(string cityname)
        {
            return maxcountinfrocity[cityname].maxcountinfrocity;
        }

        public void SetCurLookInfroRow(string cityname,string lookinfrorow)
        {
            maxcountinfrocity[cityname].curlookinfrorow = lookinfrorow;
        }

        public string GetCurLookInfroRow(string cityname)
        {
            return maxcountinfrocity[cityname].curlookinfrorow;
        }

    }

 
}
